const obj = {
    name:'liuzhiwei',
    friend: {
        name:'zhou'
    }
}

// const newObj = obj
// newObj.name = 'liu'

// 深拷贝
function deepClone(obj:Record<string, unknown>):Record<string, unknown>{
    const newObj = {}

    for(const key in obj){
        if(obj[key] instanceof Object){
            newObj[key] = deepClone(obj[key] as Record<string, unknown>)
        } else{
            newObj[key] = obj[key]
        }   
    }

    return newObj
}

function deepCloneJSON(obj:unknown):Record<string,unknown>{
    return JSON.parse(JSON.stringify(obj))
}

// done
// const newObj = deepCloneJSON(obj)
// newObj.name = 'liu'

// done
const newObj = deepClone(obj)
newObj.name = 'liu'


console.log(newObj , obj)